package com.whg.demo;

import com.bstek.ureport.console.UReportServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;
import tk.mybatis.spring.annotation.MapperScan;

import javax.servlet.MultipartConfigElement;

@SpringBootApplication
@ServletComponentScan
@MapperScan("com.whg.demo.mapper")
@EnableScheduling //开启定时任务
@EnableAsync //开启异步任务
@ImportResource("classpath:context.xml")
public class ProjectTwoApplication {
	//打war包时需要
		//extends SpringBootServletInitializer {

	/*@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(ProjectTwoApplication.class);
	}*/

	public static void main(String[] args) {
		SpringApplication.run(ProjectTwoApplication.class, args);
	}


	/**
	 * 修改文件上传的大小限制
	 * @return
	 */
	@Bean
	public MultipartConfigElement multipartConfigElement(){
		MultipartConfigFactory factory = new MultipartConfigFactory();
		//单个文件最大限制：10240KB=10MB
		factory.setMaxFileSize(DataSize.of(10240L, DataUnit.KILOBYTES));
		//设置总上传数据总大小：1024000KB=1000MB
		factory.setMaxRequestSize(DataSize.of(1024000L,DataUnit.KILOBYTES));
		return factory.createMultipartConfig();
	}

	@Bean
	public ServletRegistrationBean buildUReportServlet() {
		/**
		 * @param  servlet
		 * @param  urlMappings 值为“/ureport/*”的 urlMappings 是一定不能变的，否则系统将无法运行。
		 */
		return new ServletRegistrationBean(new UReportServlet(), "/ureport/*");

	}

}
